package com.lin.csdn.dao.impl;

import com.lin.csdn.dao.BaseDao;
import com.lin.csdn.dao.intf.IBrowseDao;
import com.lin.csdn.model.po.Picture;

import java.util.ArrayList;
import java.util.List;

public class BrowseDao extends BaseDao implements IBrowseDao{

    @Override
    public String getArticle(int blogId){
        List<Object> list=new ArrayList<>();
        list.add(blogId);
        Object result=findSingle("SELECT context FROM article where blogid=?",list);
        return String.valueOf(result);
    }

    @Override
    public void deleteArticle(int blogId){
        List<Object> list=new ArrayList<>();
        list.add(blogId);
        update("Delete From article where blogid=?",list);
    }

    @Override
    public String getPic(int blogId){
        List<Object> list=new ArrayList<>();
        list.add(blogId);
        Class<Picture> cls=Picture.class;
        Object result=find("SELECT picurl FROM picture where blogid=?",list,cls);
        return String.valueOf(result);
    }

    public int updateTdd(int blogId,String title,String description,String domain){
        List<Object> list=new ArrayList<>();
        list.add(title);
        list.add(description);
        list.add(domain);
        list.add(blogId);
        return update("UPDATE blog SET title=?, description=?,domain=? WHERE id=?",list);
    }

    public int collect(int blogId,int userId){
        List<Object> list=new ArrayList<>();
        list.add(blogId);
        list.add(userId);
        return update("INSERT INTO collect (blogid,userid) VALUES (?,?)",list);
    }

    public void target(int targetId,int userId){
        List<Object> list=new ArrayList<>();
        list.add(targetId);
        list.add(userId);
        update("INSERT INTO follow (befollowed,follow) VALUES (?,?)",list);
    }

    public String isFollow(int targetId,int userId){
        List<Object> list=new ArrayList<>();
        list.add(targetId);
        list.add(userId);
        Object result=findSingle("SELECT * FROM follow where befollowed=? and follow=?",list);
        System.out.println(result);
        if(result == null){
            return "404";
        }
        return "200";
    }

    public String isCollect(int blogId,int userId){
        List<Object> list=new ArrayList<>();
        list.add(blogId);
        list.add(userId);
        Object result=findSingle("SELECT * FROM collect where blogid=? and userid=?",list);
        if(result == null){
            return "404";
        }
        return "200";
    }
}
